package com.ken.concurrencystudy.example.reversePrint;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public int[] reversePrint(ListNode head) {

        if(head == null){
            return new int[0];
        }
        Size size = new Size();
        reversePrint(head,size);
        return size.array;
    }
    public void reversePrint(ListNode node,Size size) {
        size.size++;
        if(node.next == null){
            size.array = new int[size.size];
            size.array[size.index] = node.val;
            size.index++;
            return;
        }
        reversePrint(node.next,size);
        size.array[size.index] = node.val;
        size.index++;
    }
    class Size{
        public int size = 0;
        public int index = 0;
        public int[] array;
    }

    class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
  }
}
